package com.lzj.demo.design.builder;

import com.lzj.demo.design.builder.matter.Matter;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@AllArgsConstructor
@NoArgsConstructor
public class MenuBuilderBuilder implements IMenuBuilder {
    private List<Matter> matterList = new ArrayList<>();
    private BigDecimal price =  BigDecimal.ZERO;
    private BigDecimal area;
    private String grade;

    public MenuBuilderBuilder(BigDecimal area, String grade) {
        this.area = area;
        this.grade = grade;
    }

    @Override
    public IMenuBuilder appendCeiling(Matter matter) {
        matterList.add(matter);
        price = price.add(area.multiply(new BigDecimal("1.4").multiply(matter.price())));
        return this;
    }

    @Override
    public IMenuBuilder appendCoat(Matter matter) {
        matterList.add(matter);
        price = price.add(area.multiply(new BigDecimal("0.2").multiply(matter.price())));
        return this;
    }

    @Override
    public IMenuBuilder appendFloor(Matter matter) {
        matterList.add(matter);
        price = price.add(area.multiply(matter.price()));
        return this;
    }

    @Override
    public IMenuBuilder appendTitle(Matter matter) {
        matterList.add(matter);
        price = price.add(area.multiply(matter.price()));
        return this;
    }

    @Override
    public String getDetail() {
        StringBuilder sb = new StringBuilder();
        sb.append("\r\n ------------------------------------\r\n");
        sb.append("装修清单").append("\r\n");
        sb.append("装修等级：").append(grade).append("\r\n");
        sb.append("装修价格：").append(price.setScale(2,BigDecimal.ROUND_HALF_UP)).append("元\r\n");
        sb.append("房屋面积：").append(area.doubleValue()).append("平方米\r\n");
        sb.append("材料清单：\r\n");
        matterList.forEach(matter-> sb.append(matter.scene()).append(": ").append(matter.brand()).append("、")
                .append(matter.model()).append("、每平方米价格").append(matter.price()).append("元 \r\n"));
        return sb.toString();
    }
}
